package cn.edu.cqvie.ssm.entity;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 分页对象
 * @author zhengsh
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Page {
	
	/**
	 * 当前页号
	 */
	private int num = 1;
	
	/**
	 * 每页显示记录数量
	 */
	private int size = 5;
	
	/**
	 * 查询总记录数量
	 */
	private int rowCount = 0;
	
	/**
	 * 总页数
	 */
	private int pageCount=0;
	
	/**
	 * 当前页开始行号
	 */
	private int startRow;
	
	/**
	 * 第一页 页号
	 */
	private int first = 1;
	
	/**
	 * 最后页 页号
	 */
	private int last = 1;
	
	/**
	 * 下一页 页号
	 */
	private int next;
	
	/**
	 * 前一页 页号
	 */
	private int prev;

	public Page(int num, int size, int rowCount) {

		this.num = num;
		this.size = size;
		this.rowCount = rowCount;
		
		this.pageCount = (int) Math.ceil((double)rowCount/size);
		this.num = Math.min(this.num, this.pageCount);
		this.num = Math.max(1, this.num);
		
		this.last = this.pageCount;
		this.next = Math.min(this.pageCount, this.num + 1);
		this.prev = Math.max(1, this.num -1);
		
		this.startRow = (num -1) * size;
	}
	
	
}
